#include<bits/stdc++.h>
using namespace std;

class Solution {
public:
    int n;
    bool check(int mid,vector<int>& nums,vector<vector<int>>& q)
    {
      if(mid>=q.size()) return false;
        vector<int> vec(n+1);
        vec[0]=nums[0];
        for(int i=1;i<n;++i) vec[i]=nums[i]-nums[i-1];
        for(int i=0;i<=mid;i++)
        {
            vec[q[i][0]]-=q[i][2];
            vec[q[i][1]+1]+=q[i][2];
        }
        for(int i=0;i<n;i++) 
        {
          if(i>0) vec[i]+=vec[i-1];
          if(vec[i]>0) return false;
          }
        return true; 
    }
    int minZeroArray(vector<int>& nums, vector<vector<int>>& queries) {
        n=nums.size();
        int flag=0;
        for(int i=0;i<n;i++) if(nums[i]>0) flag=1;
        if(!flag) return 0;
        int left=0;
        int right=queries.size()-1;
        int ans=INT_MAX;
        while(left<=right)
        {
            int mid=(left+right)>>1;
            if(check(mid,nums,queries)) 
           { 
              ans=min(ans,mid+1);
              right=mid-1;
            }
            else left=mid+1;
        }
        return ans==INT_MAX?-1:ans;
    }
};

int main()
{
    vector<int> nums={2,0,2};
    vector<vector<int>> vec={{0,2,1},{0,2,1},{1,1,3}};
    Solution so;
    so.minZeroArray(nums,vec);
    return 0;
}
